use serde::Deserialize;
use serde::de::DeserializeOwned;
use std::collections::HashMap;
use std::fs::File;
use std::io::BufReader;
use std::path::Path;
use std::error::Error;

fn read_json_generic<T, P: AsRef<Path>>(path: P) -> Result<T, Box<dyn Error>>
where
    T: DeserializeOwned,
{
    let file = File::open(path.as_ref())?;
    let reader = BufReader::new(file);
    let data: T = serde_json::from_reader(reader)?;

    Ok(data)
}


pub fn main() -> Result<(), Box<dyn std::error::Error>> {
    let path = "./json/synonyms_zh.json";
    let synonym_data: HashMap<String, Vec<String>> = read_json_generic(path)
        .map_err(|e| format!("读取 {} 失败: {}", path, e))?; // 增强错误信息
    // 使用数据
    println!("身份证号同义词: {:?}", synonym_data.get("身份证号"));
    println!("完整数据: \n{:#?}", synonym_data);

    Ok(())
}
